<?php

namespace Tests;


use App\Common\Web\TempFileOther\TempFileOtherEntity;
use App\Common\WX\Wx;
use App\X\EHelper;
use PHPUnit\Framework\TestCase;
use XWX\Common\H;

class test_temp extends TestCase
{
    function test_str()
    {
        $url = 'https://www.baidu.com';
        $test = new \EasySwoole\HttpClient\HttpClient($url);
        $x = $test->get();

        var_dump($x);
//        $test->addCookie('c1','c1')->addCookie('c2','c2');
//
//        $test->setHeader('myHeader','myHeader');
//
//        $ret = $test->postJSON(json_encode(['json'=>1]));
    }


    function test_preg_match()
    {
        $text = "{include file='_app/_template/head/head.element-ui.html'}{if (a==1)}{include file='_app/_template/x.html'}";
//        $text = "123";

        $p = '#\{if (.*?)\}#';
        $x = preg_replace($p, '{\\1}', $text);
//        $x = preg_replace($p, '{aaa}', $text);
        $p = '#\{include file=\'(.*?)\'}#i';
        preg_match_all($p, $text, $match);
        var_dump($x);
        var_dump($match);
    }

    function test_array()
    {
        $ignore_field = ['b'];
        $data = [
            'a' => 1,
            'b' => 2,
            'c' => 3,
        ];
        $data = array_filter($data, function ($v, $k) use ($ignore_field)
        {
            return !in_array($k, $ignore_field);
        }, ARRAY_FILTER_USE_BOTH);


        var_dump($data);
    }

    function test_getid()
    {
        print H::today()->format('Ymd');
        print EHelper::funcGetID();
    }

    function test_db()
    {
        $wx = new Wx();
        $url = $wx->funcAppGetOAuthUrl('x', '123');

        var_dump($url);
    }

    function test_xml()
    {
        $data = " 
<note> 
<to>Tove</to> 
<from>Jani</from> 
<heading>Reminder</heading> 
<body>Don't forget me this weekend!</body> 
</note>";

        $xml = simplexml_load_string($data);
        var_dump($xml);

        $this->assertTrue(true, '123');
    }
}